package com.yuexun.dhdoctor.module.mythings.presenter.impl;



import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.bean.model.HelpFileBean;
import com.yuexun.dhdoctor.module.mythings.bean.AnnualLeaveBean;
import com.yuexun.dhdoctor.module.mythings.bean.FlowMemberData;
import com.yuexun.dhdoctor.module.mythings.bean.TypeData;
import com.yuexun.dhdoctor.module.mythings.model.IThingModel;
import com.yuexun.dhdoctor.module.mythings.presenter.IThingAddPresenter;
import com.yuexun.dhdoctor.module.mythings.ui.view.IThingAddView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/3/14.
 */
public class ThingAddPresenter implements IThingAddPresenter {
    private IThingAddView view;
    private IThingModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public ThingAddPresenter(IThingModel model, IThingAddView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getTypeDatas(Map<String, String> praise) {
        model.getTypeDatas(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<TypeData>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取类型失败");
                    }

                    @Override
                    public void onNext(BaseEntity<TypeData> typeBean) {
                        view.showTypeDatas(typeBean);
                    }
                });
    }

    @Override
    public void getHelpFile(Map<String, String> params) {
        model.getHelpFile(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HelpFileBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(HelpFileBean helpFileEntity) {
                        view.getHelpFile(helpFileEntity);
                    }
                });
    }

    @Override
    public void getFlowMember(Map<String, String> params) {
        model.getFlowMember(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<FlowMemberData>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<FlowMemberData> flowMemberData) {
                        view.getFlowMember(flowMemberData);
                    }
                });
    }

    @Override
    public void getAnnualLeave(Map<String, String> params) {
        model.inquireTaskOfZdLeaveDays(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<AnnualLeaveBean>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<AnnualLeaveBean> s) {
                        view.getAnnualLeave(s);
                    }
                });
    }
}
